Skip to content

feat: AI alerts checked by the analyst agent - #10231

Open
nishantmonu51 wants to merge 9 commits into
nishant/resolver-props-yamlfrom
nishant/ai-alerts
Open

nishantmonu51 wants to merge 9 commits into
nishant/resolver-props-yamlfrom
nishant/ai-alerts

Conversation

@nishantmonu51

@nishantmonu51 nishantmonu51 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Takes over #10120 from its contributor and addresses its review. It's the first of a stack: #10229 (base) → this → #10232 (admin API) → #10233 (chat alerts) → #10234 (chat reports).

An alert's condition can be written in words (data: ai: {prompt, explore, ...}). Every check runs the analyst on it, then a tool-less structured call classifies the analysis as met, not_met or cannot_determine.

  • Verdict: the normal analyst loop runs, with the number check from fix(ai): check that the analyst's numbers come from tool results #10131, and starts its answer with a <summary>. The separate verdict call works with providers that reject tools combined with an output schema. FailOnIterationLimit is gone.
  • Outcomes: met fires the alert with the summary as the reason. cannot_determine, for example a condition on a measure that doesn't exist, fails the check with an error instead of reporting "not met".
  • Scheduling: the parser requires refresh.cron at most once an hour, rejects ref_update, tickers and intervals, and requires for.user_id (the session's owner). The dialog offers only a schedule for AI conditions.
  • Notifications: email and Slack show the reason instead of rows (with notify.rows_limit from feat: list matching rows in alert notifications with notify.rows_limit #10140) and link to the analysis. The open page redirects to the conversation.
  • Claims: AI alerts run with alertQueryClaims (feat: support alerts for embedded users #10148), plus the owner as session user and the permissions AI reports get.
  • Dialog: redone on main's rewritten dialog with a Criteria / AI condition switch, hidden in embeds. The measure filter subquery is converted to the resolver's shape, and the alert page links through getMappedUrl like AI reports.
  • Simplifications:
    • Dropped the SkipChecks guard and the chart exclusion.
    • The inherited watermark code is shared with reports.
    • Reuses mapResolverExpressionToV1Expression and AIResolverProps.
    • No longer preserves unknown ai properties.
  • Eval: TestAnalystAlertEval (expensive) adds a cannot-determine case.

Known gaps:

  • Main's schedule form can't show an hourly cron: it reloads as daily and would save 0 NaN * * * (reports have the same problem). So editing an hourly AI alert created from the chat breaks.
  • Not yet checked in a browser.

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

dfliess and others added 6 commits November 7, 2026 12:59
…YAML

Alerts and reports created through the API with a resolver serialized its
properties as the protobuf Struct's internals (fields/kind/stringvalue), so
the runtime parsed different properties than it was given.
An alert with the ai resolver has its prompt judged as a condition by the
analyst agent, which ends with a structured verdict. A met condition returns
one row with the verdict's reason and the conversation, so the alert fires;
a malformed verdict or an exhausted tool budget is an evaluation error.
The check runs with the alert's own claims, and notifications show the
reason and link to the conversation.
The data tab switches between criteria and an AI condition written as a
sentence. AI alerts load into and save from the dialog however they were
created, and the alert page and history show the condition and the reason
an AI alert triggered.
Conflicts with main:
- Notifications read rows with `notify.rows_limit` (#10140). An AI alert shows the analysis's reason instead of rows.
- Alerts run with `alertQueryClaims` (#10148). An AI alert's session is owned by its "for" user, which the parser now requires.
- The alert dialog was rewritten on main. The merge takes main's dialog; the AI condition is redone on top of it.

Review changes:
- The parser limits AI alerts to a cron schedule of at most once an hour, without `ref_update`, a ticker or `intervals`.
- The verdict is a separate, tool-less structured call after the normal analyst loop, so it works with providers that reject tools combined with an output schema, and the analysis keeps the number check from #10131. `FailOnIterationLimit` is gone.
- The verdict can be "cannot_determine", which fails the check with an error instead of reporting "not met".
- The reason shown in notifications is the analysis's summary, so its numbers are the checked ones.
- Drop the unreachable `SkipChecks` guard and the redundant chart exclusion.
- Share the inherited watermark code between the alert and report reconcilers.
convertV1ExpressionToMapstructure passed a measure filter's subquery through in its proto shape,
which Go's metricsview.Subquery can't decode.
It now names the dimension and measures as objects and converts the subquery's where and having,
the inverse of mapResolverExpressionToV1Expression,
which also replaces the duplicate convertMapstructureToV1Expression.
- The data tab switches between criteria and an AI condition (not offered for alerts created from an embed).
  In AI mode the measure is optional, the split has no rows limit and the time filters offer no comparison.
- The criteria tab takes the condition, which names the alert by default.
- AI alerts save the `ai` resolver's properties (AIResolverProps plus the prompt) from what the dialog shows:
  the measure, dimension, filters, time range and zone. Nothing the dialog doesn't edit is kept.
- AI alerts are always checked on a schedule (daily or rarer), never when data refreshes, and attach no rows.
- Editing an AI alert reads its resolver properties back into the form and the filters,
  and waits for the explore's metrics view, which the properties don't name.
- The alert page links AI alerts to their explore through the "ai" url source and shows the condition;
  the open route sends AI alerts to the conversation behind the check.
@nishantmonu51 nishantmonu51 added Type:Feature New feature request Area:Alerts Size:L Large change: 500-1,999 lines Area:AI AI assistant, chat and agents labels Nov 28, 2026
@nishantmonu51
nishantmonu51 requested a review from pjain1 November 28, 2026 07:25

@nishantmonu51 nishantmonu51 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things inline on editing and delivering these alerts.

(isEmbedded && $embedOpenUrlQuery.isPending) ||
!exploreState
!exploreState ||
!metricsViewName

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also blocks existing criteria alerts that have no web_open_path and whose metrics view name differs from their Explore name. getAlertDashboardName falls back to the metrics view, useExploreValidSpec finds no Explore by that name, and Edit opens with no form. Could we keep the saved-query path for criteria alerts and require the Explore lookup only for AI alerts that need it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving as is: on main the dialog for such an alert opens without its filters, and saving it drops the saved where and time range and writes a web_open_path to a missing explore (I checked this in the dialog spec), so waiting for the explore is the safer outcome. Dialog and chat-created alerts always record their explore, and looking it up by metrics view can be a follow-up; 51d3949 adds a comment saying why.

// Its condition says what to compare with, so the time filters don't offer a comparison.
$: isAIAlert = $form["conditionType"] === AIConditionType;
const aiTimeFiltersConfig: TimeFiltersConfig = {
showTimeDimensionSelector: true,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On an Explore with multiple time dimensions, selecting a secondary date here saves time_range.time_dimension, but ResolveInteractive gives AnalystAgentArgs only the start and end. The analyst has no record of which date field the user chose, so it can check the same window on the primary date instead. Could we pass the selected time dimension through to the analyst's query context, or hide this picker for AI alerts until that works?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 51d3949: AI alerts hide the time dimension picker and no longer save time_range.time_dimension, since the analyst only gets the start and end; passing it through to the analyst can be a follow-up.

prompt: values.aiCondition.trim(),
explore: values.exploreName,
};
if (values.measure) props.measures = [values.measure];

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alert created from an Explore's formula measure can still select that measure in AlertDialogDataTab, and getNewAlertInitialFormValues can select it by default. The AI resolver only gets its name, so the analyst can't resolve the formula from the metrics view. Could we exclude formula measures in AI mode and clear an inherited formula selection when switching to it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 51d3949: in AI mode the measure picker leaves out ephemeral measures, and switching to an AI condition clears an inherited one (new case in AlertDialogDataTab.spec.ts).

// The runtime adds the session ID to the open link, which keeps opening the conversation if the alert was switched to criteria since.
// In creator mode the link also carries a magic token, which grants read access to the shared conversation and must be forwarded.
const sessionId = url.searchParams.get("session_id");
if (sessionId || isAIAlertSpec(alertSpec)) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles old AI notifications after switching to Criteria, but switching the other way sends old Criteria notifications with an execution_time and no session_id to the AI home. Could we use session_id as the redirect signal and keep a dashboard or alert-details fallback for links without a conversation?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 51d3949: only a session_id redirects to the conversation; links without one go through AlertOpen, which opens the dashboard, or the alert page when the alert has no query.

return errors.New(`AI alerts can't set "intervals", since every interval is a separate AI analysis`)
}
if queryForUserID == "" {
return errors.New(`AI alerts must set "for.user_id", the user whose access and AI session the analysis runs with`)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add an example to docs/docs/reference/project-files/alerts.md? An author adding data.ai to an existing YAML alert also has to set for.user_id, switch to an hourly-or-slower refresh.cron, and remove intervals. The current reference gives them no AI alert example to start from.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 51d3949: added an AI alert example with for.user_id, an hourly-or-slower cron and no intervals, corrected "Only available for reports", and extended the schema examples test to parse the alert examples.

Comment thread runtime/reconcilers/alert.go Outdated
Comment on lines +1323 to +1327
link, err := addExecutionTime(openURL, executionTime)
if err != nil || aiSessionID == "" {
return link, err
}
return buildAISessionURL(link, aiSessionID)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could alertOpenLink set execution_time and the optional session_id in one pass through url.Parse and url.ParseQuery? addExecutionTime only has this caller, and buildAISessionURL reparses the same URL. The report caller can keep using buildAISessionURL.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 51d3949: alertOpenLink now sets both parameters in one pass, addExecutionTime is gone, and TestAlertOpenLink covers both cases.

… review

- AI alerts no longer offer or save a secondary time dimension, which the analyst never gets.
- AI alerts no longer offer ephemeral measures, and switching to an AI condition clears one.
- Only a `session_id` sends an alert's open link to the AI conversation; other links open the dashboard or the alert's page.
- `alertOpenLink` sets `execution_time` and `session_id` in one pass.
- The alert reference gets an AI alert example, and the AI resolver is documented as available for alerts.
@pjain1

pjain1 commented Nov 29, 2026

Copy link
Copy Markdown
Member

Thanks for taking this over. The separate tool-less verdict call, the cannot_determine outcome and the parser's scheduling rules are what we wanted, and the three frontend findings from the first review are fixed. A few things remain.

Errors on AI alerts are invisible. Managed alerts do not notify on error by default, so an alert whose condition ends in cannot_determine fails on every check and the owner only finds out by opening the alert page. Please set on_error: true for AI alerts in yamlForManagedAlert. The cost is an email when the provider has a transient failure, at most once per check, which is acceptable.

Reason fallback. When the model omits the <summary> tag, the resolver uses the whole response as the notification's reason. Please truncate it in that case.

Browser check. The description says the dialog has not been checked in a browser yet. Please do that before merging, since the frontend was redone on the rewritten dialog.

Schedules. The dialog offering only daily, weekday, weekly and monthly schedules for AI conditions is fine. The parser's hourly limit then only matters for alerts written in project files.

Smaller points.

  • In alert-dialog.component.spec.ts, the second test covers an alert created through the API and can go. The third test is one assertion on aiConditionAllowed and fits in the existing AlertDialogDataTab.spec.ts.
  • The comment in AlertDialogDeliveryTab.svelte says "at most once a day", while the rule is once an hour.

Developed in collaboration with Claude Code

…y after review

- Managed AI alerts set on_error, since a check fails when the analysis can't determine whether the condition holds.
- Without a <summary> tag, the reason is the start of the analysis, cut to 500 characters like an AI report's summary.
- The dialog spec drops the test of an alert created through the API, and the data tab spec checks that the AI condition can be hidden.
- The delivery tab says the parser allows at most one check an hour.
@nishantmonu51

Copy link
Copy Markdown
Collaborator Author

@pjain1 Thanks, handled in 93771e7:

  • Errors: managed AI alerts now set on_error: true.
  • Reason fallback: without a <summary> tag, the reason is the start of the analysis, cut to 500 characters like an AI report's summary.
  • Browser check: done in Chrome against a local runtime with a stand-in admin API. Creating an AI alert from an explore sends resolver: ai with the condition, filters, measure and time range, offers only a schedule (daily, weekdays, weekly, monthly) and no attachment; editing a saved AI alert reopens it in AI mode with its condition, time range and measure; switching back to Criteria still saves a query alert. Delivery and a scheduled run need a real admin service and weren't checked.
  • Schedules: left as is.
  • Smaller points: dropped the API-created alert test, moved the embed check into AlertDialogDataTab.spec.ts, and the delivery tab comment now says at most once an hour.

@nishantmonu51 nishantmonu51 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing on Slack error delivery.

Comment thread admin/server/alerts.go
}
// Notification options
// An AI alert's check fails when the analysis can't determine whether its condition holds, so its owner hears about errors.
res.OnError = opts.Resolver == "ai"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With on_error enabled, a cannot_determine reason goes through SendAlertStatus as ExecutionError. That branch puts the analyst’s text straight into Slack markup, so angle-bracketed text can turn into a link or mention. Could we use slackTextEscaper.Replace(s.ExecutionError) for ErrorMessage, like the alert-triggered branch does for Reason? Slack’s escaping rules

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 14c91f5: the error branch now escapes ExecutionError with slackTextEscaper, for every alert, and the Slack notifier test covers it.

With on_error set for AI alerts, a cannot_determine error carries the analysis's text, so it's escaped like an AI alert's reason.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area:AI AI assistant, chat and agents Area:Alerts Size:L Large change: 500-1,999 lines Type:Feature New feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants